package com.wbao.dianniu.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.data.ActivityListData;
import com.wbao.dianniu.utils.PictureDownloadUtils;
import com.wbao.dianniu.utils.Utils;

/**
 * 我发布的活动
 *
 * @author yejianjun
 */
public class IPartinActiveAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<ActivityListData> mList;

    public IPartinActiveAdapter(Context context) {
        mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (null == mList)
            mList = new ArrayList<ActivityListData>();
    }

    //	public void setData(List<ActivityListData> list){
//		mList = list;
//	}
    public void clearData() {
        if (null != mList) {
            mList.clear();
        }
    }

    public void addData(List<ActivityListData> list) {
        if (null == list)
            return;
        for (int i = 0; i < list.size(); i++) {
            mList.add(list.get(i));
        }
    }

    public List<ActivityListData> getList() {
        return mList;
    }
//	public void addTopData(ActivityListData data){
//		mList.add(0, data);
//	}

    @Override
    public int getCount() {
        if (null == mList)
            return 0;
        else
            return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        GridHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.partin_activity_list_item, null);
            holder = new GridHolder();
            holder.headIV = convertView.findViewById(R.id.user_head);
            holder.nameTV = convertView.findViewById(R.id.user_name);
            holder.labelTV = convertView.findViewById(R.id.user_label);
            holder.sexIV = convertView.findViewById(R.id.user_sex);
            holder.partnerIV = convertView.findViewById(R.id.user_partner);
            holder.addV = convertView.findViewById(R.id.add_v_iv);
            holder.subjectTV = convertView.findViewById(R.id.partIn_subject);
            holder.maxPersionTV = convertView.findViewById(R.id.partIn_maxPersion);
            holder.startDateTV = convertView.findViewById(R.id.partIn_startDate);
            holder.priceTV = convertView.findViewById(R.id.partIn_price);
            holder.addressTV = convertView.findViewById(R.id.partIn_address);
            holder.joinStatusTV = convertView.findViewById(R.id.partIn_join_status);
            holder.resultTV = convertView.findViewById(R.id.partIn_result);
            convertView.setTag(holder);
        } else {
            holder = (GridHolder) convertView.getTag();
        }
        ActivityListData data = mList.get(position);
        if (null != data) {
            PictureDownloadUtils.displayHeadImage(mContext, holder.headIV, data.getHeadPic());
            holder.nameTV.setText(data.getRealName() == null ? "" : data.getRealName());
            holder.labelTV.setText(data.getLabel() == null ? "" : data.getLabel());
            Utils.showSex(mContext, data.getUserInfo().sex, holder.sexIV);
            Utils.showPartner(mContext,data.getUserInfo().partner,holder.partnerIV);
            Utils.showAuth(data.getUserInfo(),holder.addV);
            holder.subjectTV.setText(data.getSubject() == null ? "" : data.getSubject());
            holder.maxPersionTV.setText(data.getMaxPersion() + "人");
            holder.startDateTV.setText(data.getStartDate() == null ? "" : data.getStartDate());
            holder.priceTV.setText(data.getPrice() + "元/人");
            holder.addressTV.setText(data.getAddress() == null ? "" : data.getAddress());
            holder.joinStatusTV.setText(data.getInStatusDesc() == null ? "" : data.getInStatusDesc());
            if (Utils.IsActivityStart(data.getStartDate())) {
                holder.resultTV.setText("已结束");
            } else {
                holder.resultTV.setText("未开始");
            }
        }
        return convertView;
    }

    private class GridHolder extends UserInfoHolder {
        public TextView subjectTV;
        public TextView maxPersionTV;
        public TextView startDateTV;
        public TextView priceTV;
        public TextView addressTV;
        public TextView joinStatusTV;
        public TextView resultTV;
    }
}
